numHotspots = 2 #Number of hotspots to check
differentPixelsPercentageThreshold = [5.0, 10.0] #For each hotspot
sizeMotionCheckWindow = (40, 30) #For all hotspots

def MD(prevVFFrame, crtVFFrame):
    global numHotspots, hotspot, differentPixelsPercentageThreshold

    for hotspotIndex in range(0, numHotspots):
        width, height = crtVFFrame.size
        #Draw a red rectangle for each hotspot.
        crtVFFrame.rectangle([ (hotspot[hotspotIndex][0][0] * width, hotspot[hotspotIndex][0][1] * height), (hotspot[hotspotIndex][1][0] * (width - 1), hotspot[hotspotIndex][1][1] * (height - 1))], 0xff0000)
        stepX = int(width / sizeMotionCheckWindow[0])
        stepY = int(height / sizeMotionCheckWindow[1])
        differentPixelsThreshold = sizeMotionCheckWindow[0] * sizeMotionCheckWindow[1] * differentPixelsPercentageThreshold[hotspotIndex] / 100.0
        numDifferentPixels = 0
        for y in range( int(hotspot[hotspotIndex][0][1] * height), int(hotspot[hotspotIndex][1][1] * (height - 1)), stepY):
            for x in range( int(hotspot[hotspotIndex][0][0] * width), int(hotspot[hotspotIndex][1][0] * (width - 1)), stepX):
                r, g, b = crtVFFrame.getpixel( (x, y) )[0]
                prevr, prevg, prevb = prevVFFrame.getpixel( (x, y) )[0]
                delta = abs(r - prevr) + abs(g - prevg) + abs(b - prevb)
                if (delta > 3 * 10):
                    numDifferentPixels += 1
                    if (numDifferentPixels > differentPixelsThreshold):
                        return True

    return False
